package org.ftc.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ftc.domain.InCharge;
import org.ftc.form.InChargeForm;
import org.ftc.service.FtcLogService;
import org.ftc.service.FtcLogService.Log;
import org.ftc.service.InChargeService;
import org.ftc.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller 
public class InChargeController {
	@Autowired
	UsersService usersService;
	@Autowired
	InChargeService inChargeService;
	@Autowired
	FtcLogService logService;
	
	@RequestMapping(value = "/inCharge.htm")
	public String inCharge(ModelMap model) {
		return "inCharge/list";
	}

	@RequestMapping(value = "/inCharge/list.json", method = RequestMethod.POST)
	public @ResponseBody
	Map<String, Object> find(InChargeForm searchForm, BindingResult binding, ModelMap model) {
		logService.before();
		Map<String, Object> json = new HashMap<String, Object>();
		List<InCharge> data = inChargeService.findAll();
		json.put("rows", data);
		logService.save(Log.QUERY, this.getClass().toString());
		return json;
	}

//	@RequestMapping(value = "/inCharge/update.json", method = RequestMethod.POST)
//	public @ResponseBody String save(InCharge entity, ModelMap model) {
//		logService.before();
//		boolean result = false;
//		if(entity==null || StringUtils.isBlank(entity.getName())){
//			return "true";
//		}else{
//			InCharge inCharge = inChargeService.get(entity.getIcSeq());
//			if(inCharge==null){
//				result = inChargeService.save(entity);
//				logService.save(Log.INSERT, entity.getIcSeq(), this.getClass().toString() ,ToStringBuilder.reflectionToString(entity));
//				return result?"save":"false";
//			}else{
//				inCharge.setName(entity.getName());
//				result = inChargeService.update(inCharge);
//				logService.save(Log.UPDATE, entity.getIcSeq(), this.getClass().toString() ,ToStringBuilder.reflectionToString(entity));
//				return result?"update":"false";
//			}
//		}
//	}
	
	private void save(){
		List<InCharge> list = new ArrayList<>();
		list.add(gen("203"	, "洪萱","洪萱"    ) );
		list.add(gen("204"	, "黃佩琳","洪萱"  ) );
		list.add(gen("205"	, "林馨文","洪萱"  ) );
		list.add(gen("206"	, "鍾佳純","洪萱"  ) );
		list.add(gen("207"	, "孫綺君","洪萱"  ) );
		list.add(gen("208"	, "","洪萱"        ) );
		list.add(gen("209"	, "梁詠鈞","洪萱"  ));
		list.add(gen("211"	, "王政傑","任漢瑛"));
		list.add(gen("212"	, "","任漢瑛"      ));
		list.add(gen("213"	, "賴加慶","任漢瑛"));
		list.add(gen("214"	, "陳瑾儀","任漢瑛"));
		list.add(gen("216"	, "陳世芳","侯文賢"));
		list.add(gen("217"	, "朱俐蓁","任漢瑛" ));
		list.add(gen("218"	, "林本源","洪萱  " ));
		list.add(gen("219"	, "康婕 ","侯文賢"  ));
		list.add(gen("221"	, "吳政道","侯文賢" ));
		list.add(gen("222"	, "張佩璘","侯文賢" ));
		list.add(gen("223"	, "陳蓬芳","侯文賢" ));
		list.add(gen("224"	, "",""           )  );
		list.add(gen("303"	, "林政羽","洪秀幸" ));
		list.add(gen("304"	, "林靜渝","洪秀幸" ));
		list.add(gen("305"	, "戴美琴","洪秀幸" ));
		list.add(gen("306"	, "蔡惠琦","洪秀幸" ));
		list.add(gen("307"	, "陳盈儒","洪秀幸" ));
		list.add(gen("308"	, "","洪秀幸"       ) );
		list.add(gen("310"	, "張心怡","郭安琪" ));
		list.add(gen("311"	, "方彥修","郭安琪" ));
		list.add(gen("312"	, "",""           ) );
		list.add(gen("313"	, "黃曉吟","郭安琪"));
		list.add(gen("314"	, "沈立委","郭安琪"));
		list.add(gen("315"	, "詹麗玲","郭安琪"));
		list.add(gen("317"	, "賴心儀","廖賢洲"));
		list.add(gen("318"	, "曾久珍","廖賢洲"));
		list.add(gen("319"	, "曹惠雯","廖賢洲"));
		list.add(gen("320"	, "楊中琳","廖賢洲"));
		list.add(gen("321"	, "蔡靜慧","廖賢洲"));
		list.add(gen("322"	, "林靜渝","廖賢洲"));
		list.add(gen("324"	, "林學良","邱淑芬"));
		list.add(gen("325"	, "","邱淑芬"      ));
		list.add(gen("326"	, "徐倬園","邱淑芬"));
		list.add(gen("327"	, "徐秀鳳","邱淑芬"));
		list.add(gen("328"	, "楊翔宇","邱淑芬"));
		list.add(gen("343"	, "簡浩羽","楊佳慧" ) );
		list.add(gen("344"	, "吳信德","楊佳慧" ) );
		list.add(gen("345"	, "胡俊賢","楊佳慧" ) );
		list.add(gen("346"	, "王性淵","楊佳慧" ) );
		list.add(gen("347"	, "黃嘉琪","楊佳慧" ) );
		list.add(gen("348"	, "黃曉吟","楊佳慧" ) );
		list.add(gen("351"	, "馬明玲","吳麗玲" ) );
		list.add(gen("353"	, "曾惠怡","林金郎" ) );
		list.add(gen("354"	, "吳建興","林金郎" ) );
		list.add(gen("355"	, "林曉鴻","林金郎" ) );
		list.add(gen("357"	, "陳淑華","吳麗玲" ) );
		list.add(gen("358"	, "陳浩凱","林金郎" ) );
		list.add(gen("359"	, "劉又銓","吳麗玲" ) );
		list.add(gen("360"	, "廖儷珺","吳麗玲" ) );
		list.add(gen("361"	, "林慧美","吳麗玲" ) );
		list.add(gen("362"	, "洪進安","孫雅娟代"));
		list.add(gen("364"	, "葉素燕","吳麗玲"  ));
		list.add(gen("365"	, "劉錦智","孫雅娟代"));
		list.add(gen("366"	, "蔡聰勇","孫雅娟代"));
		list.add(gen("367"	, "","孫雅娟代"      ) );
		list.add(gen("369"	, "王鴻初","孫雅娟代" ));
		list.add(gen("370"	, "","孫雅娟代"     ));
		list.add(gen("403"	, "徐宗佑","陳人鸚" ));
		list.add(gen("404"	, "吳佳陵","陳人鸚" ));
		list.add(gen("405"	, "吳佩璠","陳人鸚" ));
		list.add(gen("406"	, "溫哲嘉","陳人鸚" ));
		list.add(gen("407"	, "林佳德","陳人鸚" ));
		list.add(gen("408"	, "莊靖怡","陳人鸚" ));
		list.add(gen("410"	, "楊佳綾","楊琇雲" ));
		list.add(gen("411"	, "游逸風","楊琇雲" ));
		list.add(gen("412"	, "李淑華","楊琇雲" ));
		list.add(gen("413"	, "林彥光","楊琇雲" ));
		list.add(gen("414"	, "蘇敏煌","楊琇雲" ));
		list.add(gen("415"	, "何彥蓉","楊琇雲" ));
		list.add(gen("417"	, "","戚雪麗"       )  );
		list.add(gen("418"	, "賴建勝","戚雪麗"   ));
		list.add(gen("419"	, "王宏炫","戚雪麗"   ));
		list.add(gen("420"	, "陳建宇","戚雪麗"   ));
		list.add(gen("421"	, "簡佳盈","戚雪麗"   ));
		list.add(gen("422"	, "李碧玲","戚雪麗"   ));
		list.add(gen("424"	, "陳威帆","賴美華"   ));
		list.add(gen("425"	, "枋惟詳","賴美華"   ));
		list.add(gen("426"	, "李婉君","賴美華"   ));
		list.add(gen("427"	, "王俊雯","賴美華"   ));
		list.add(gen("428"	, "林雨菁","賴美華"   ));
		list.add(gen("429"	, "黃麗明","賴美華"   ));
		list.add(gen("443"	, "吳侑倫","戴貝宜"   ));
		list.add(gen("445"	, "杜幸峰","顏家琳"   ));
		list.add(gen("448"	, "","   顏家琳"     ));
		list.add(gen("451"	, "陳淑芳","顏家琳"  ));
		list.add(gen("453"	, "陳立哲","戴貝宜"  ));
		list.add(gen("454"	, "林文宏","顏家琳"  ));
		list.add(gen("455"	, "謝秀玲","戴貝宜"  ));
		list.add(gen("457"	, "邱佳芸","蔣國綸"  ));
		list.add(gen("458"	, "楊琬菁","戴貝宜"  ));
		list.add(gen("459"	, "何佩雯","蔣國綸" ));
		list.add(gen("461"	, "林倩青","蔣國綸" ));
		list.add(gen("463"	, "劉紹貞","顏家琳" ));
		list.add(gen("464"	, "周宜佩","蔣國綸" ));
		list.add(gen("483"	, "李玉娟","詹秋玫" ));
		list.add(gen("487"	, "許俊雄","陳韻珊" ));
		list.add(gen("488"	, "鄭琇仁","陳韻珊" ));
		list.add(gen("490"	, "郭惠君","蔣國綸" ));
		list.add(gen("502"	, "李秀玲","張志斌" ));
		list.add(gen("545"	, "張綺娟","賴筱綾" ));
		list.add(gen("550"	, "徐雲英","賴筱綾" ));
		for(InCharge ic:list){
			inChargeService.save(ic);
		}
		
		
	}
	
	private InCharge gen(String telNo, String name1,String name2){
		InCharge ic = new InCharge();
		ic.setTelNo(telNo);
		ic.setName(name1);
		ic.setSectionChief(name2);
		return ic;
	}
	
	@RequestMapping(value = "/inCharge/findAll.json", method = RequestMethod.GET)
	public @ResponseBody
	List<InCharge> findAll() {
		return inChargeService.findAll();
	}


}
